package com.fw.ui.view.settings.usercontrol.bouser.event;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.ui.view.event.AbstractBlurListener;
import com.fw.ui.view.settings.usercontrol.bouser.CreateBOUserView;
import com.vaadin.event.FieldEvents.BlurEvent;

@Component
@Scope(SCOPE_PROTOTYPE)
public class CreateBOUserGroupBlurListener extends AbstractBlurListener {

    private static final long serialVersionUID = 1L;

    @Override
    public boolean validate(BlurEvent event) throws Exception {
	CreateBOUserView createBOUserView = (CreateBOUserView) this.getBasedComponent();
	createBOUserView.getRow6Validate().setVisible(false);
	createBOUserView.getLblGroupValidateMessage().setValue("");
	createBOUserView.getCbbGroup().removeStyleName("v-filterselect-error");
	boolean groupValid = createBOUserView.getCbbGroup().isValid();
	if (!groupValid) {
	    createBOUserView.getCbbGroup().addStyleName("v-filterselect-error");
	    if (createBOUserView.getCbbGroup().getErrorMessage() != null) {
		createBOUserView.getLblGroupValidateMessage().setValue(
			createBOUserView.getCbbGroup().getErrorMessage().getFormattedHtmlMessage());
	    }
	    createBOUserView.getRow6Validate().setVisible(true);
	}
	return true;
    }

    @Override
    public void change(BlurEvent event) throws Exception {
	// TODO Auto-generated method stub

    }

}
